{{#if async}}async {{/if}}def _{{#if async}}a{{/if}}{{operationId}}_oapg(
{{> endpoint_args isOapg=true isOverload=false skipDeserialization="null" contentType="null" interface=false}}
    """
{{#if summary}}
    {{summary}}
{{/if}}
    :param skip_deserialization: If true then api_response.response will be set but
        api_response.body and api_response.headers will not be deserialized into schema
        class instances
    """
{{#if queryParams}}
    self._verify_typed_dict_inputs_oapg(RequestQueryParams, query_params)
{{/if}}
{{#if headerParams}}
    self._verify_typed_dict_inputs_oapg(RequestHeaderParams, header_params)
{{/if}}
{{#if pathParams}}
    self._verify_typed_dict_inputs_oapg(RequestPathParams, path_params)
{{/if}}
{{#if cookieParams}}
    self._verify_typed_dict_inputs_oapg(RequestCookieParams, cookie_params)
{{/if}}
    used_path = path.value
{{#if pathParams}}

    _path_params = {}
    for parameter in (
{{#each pathParams}}
        request_path_{{paramName}},
{{/each}}
    ):
        parameter_data = path_params.get(parameter.name, schemas.unset)
        if parameter_data is schemas.unset:
            continue
        serialized_data = parameter.serialize(parameter_data)
        _path_params.update(serialized_data)

    for k, v in _path_params.items():
        used_path = used_path.replace('{%s}' % k, v)
{{/if}}
{{#if queryParams}}

    prefix_separator_iterator = None
    for parameter in (
{{#each queryParams}}
        request_query_{{paramName}},
{{/each}}
    ):
        parameter_data = query_params.get(parameter.name, schemas.unset)
        if parameter_data is schemas.unset:
            continue
        if prefix_separator_iterator is None:
            prefix_separator_iterator = parameter.get_prefix_separator_iterator()
        serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
        for serialized_value in serialized_data.values():
            used_path += serialized_value
{{/if}}

    _headers = HTTPHeaderDict()
{{#if headerParams}}
    for parameter in (
{{#each headerParams}}
        request_header_{{paramName}},
{{/each}}
    ):
        parameter_data = header_params.get(parameter.name, schemas.unset)
        if parameter_data is schemas.unset:
            continue
        serialized_data = parameter.serialize(parameter_data)
        _headers.extend(serialized_data)
{{/if}}
    # TODO add cookie handling
{{#if produces}}
    if accept_content_types:
        for accept_content_type in accept_content_types:
            _headers.add('Accept', accept_content_type)
{{/if}}
    method = '{{httpMethod}}'.upper()
{{#unless bodyParam}}
    request_before_hook(
        resource_path=used_path,
        method=method,
        configuration=self.api_client.configuration,
        path_template='{{{path}}}',
{{#if authMethods.length}}
        auth_settings=_auth,
{{/if}}
        headers=_headers,
    )
{{/unless}}
{{#with bodyParam}}
    _headers.add('Content-Type', content_type)

{{#if required}}
    if body is schemas.unset:
        raise exceptions.ApiValueError(
            'The required body parameter has an invalid value of: unset. Set a valid value instead')
{{/if}}
    _fields = None
    _body = None
    request_before_hook(
        resource_path=used_path,
        method=method,
        configuration=self.api_client.configuration,
        path_template='{{{path}}}',
        body=body,
{{#if authMethods.length}}
        auth_settings=_auth,
{{/if}}
        headers=_headers,
    )
{{#if required}}
    {{> endpoint_body_serialization }}
{{else}}
    if body is not schemas.unset:
        {{> endpoint_body_serialization }}
{{/if}}
{{/with}}
{{#if servers}}

    host = self._get_host_oapg('{{operationId}}', _servers, host_index)
{{/if}}

    response = {{#if async}}await {{/if}}self.api_client.{{#if async}}async_{{/if}}call_api(
        resource_path=used_path,
        method=method,
{{#or headerParams bodyParam produces}}
        headers=_headers,
{{/or}}
{{#if bodyParam}}
        fields=_fields,
        serialized_body=_body,
        body=body,
{{/if}}
{{#if hasAuthMethods}}
        auth_settings=_auth,
{{/if}}
{{#if servers}}
        host=host,
{{/if}}
{{#if queryParams}}
        prefix_separator_iterator=prefix_separator_iterator,
{{/if}}
        timeout=timeout,
{{#if async}}
        **kwargs
{{/if}}
    )
    {{#if async}}

    if stream:
        if not 200 <= response.http_response.status <= 299:
            body = (await response.http_response.content.read()).decode("utf-8")
            raise exceptions.ApiStreamingException(
                status=response.http_response.status,
                reason=response.http_response.reason,
                body=body,
            )

        async def stream_iterator():
            """
            iterates over response.http_response.content and closes connection once iteration has finished
            """
            async for line in response.http_response.content:
                if line == b'\r\n':
                    continue
                yield line
            response.http_response.close()
            await response.session.close()
        return AsyncGeneratorResponse(
            content=stream_iterator(),
            headers=response.http_response.headers,
            status=response.http_response.status,
            response=response.http_response
        )
    {{/if}}

    response_for_status = _status_code_to_response.get(str(response.http_response.status))
    if response_for_status:
        api_response = {{#if async}}await {{/if}}response_for_status.deserialize{{#if async}}_async{{/if}}(
                                                response,
                                                self.api_client.configuration,
                                                skip_deserialization=skip_deserialization
                                            )
    else:
        {{#if hasDefaultResponse}}
        default_response = _status_code_to_response.get('default')
        if default_response:
            api_response = default_response.deserialize(
                                                response,
                                                self.api_client.configuration,
                                                skip_deserialization=skip_deserialization
                                            )
        else:
            api_response = api_client.ApiResponseWithoutDeserialization{{#if async}}Async{{/if}}(
                response=response.http_response,
                round_trip_time=response.round_trip_time,
                status=response.http_response.status,
                headers=response.http_response.headers,
            )
        {{else}}
        # If response data is JSON then deserialize for SDK consumer convenience
        is_json = api_client.JSONDetector._content_type_is_json(response.http_response.headers.get('Content-Type', ''))
        api_response = api_client.ApiResponseWithoutDeserialization{{#if async}}Async{{/if}}(
            body={{#if async}}await response.http_response.json(){{else}}json.loads(response.http_response.data){{/if}} if is_json else {{#if async}}await response.http_response.text(){{else}}response.http_response.data{{/if}},
            response=response.http_response,
            round_trip_time=response.round_trip_time,
            status=response.http_response.status,
            headers=response.http_response.headers,
        )
        {{/if}}

    if not 200 <= api_response.status <= 299:
        raise exceptions.ApiException(api_response=api_response)
    {{#if async}}

    # cleanup session / response
    response.http_response.close()
    await response.session.close()
    {{/if}}

    return api_response
